#pragma once

#include "../RHIResource.h"

class RHIFence : public RHIResource
{
	struct BuilderDetails {

		bool isSignaled;
		uint32 count;

		BuilderDetails();
	};

public:

	class Builder : public BuilderBase<BuilderDetails> {
		friend struct BuilderDetails;
	public:
		Builder() noexcept;
		Builder(Builder const& rhs) noexcept;
		Builder(Builder&& rhs) noexcept;
		~Builder() noexcept;
		Builder& operator=(Builder const& rhs) noexcept;
		Builder& operator=(Builder&& rhs) noexcept;

		Builder& SetSignaled(bool isSignaled) noexcept;
		Builder& SetCount(uint32 count) noexcept;

		RefCountPtr<RHIFence> Build();
		RefCountPtr<RHIFence> Build(RenderProcess* process, const std::string& name);

	private:

		friend class RHIFence;
	};

	RHIFence(BuilderDetails& builderDetails);

	virtual void ReleaseResource() override;

	virtual ~RHIFence();

public:

	VkFence GetFence(uint32 index = UINT32_MAX) const;

	bool IsSignaled(uint32 index = UINT32_MAX) const;

	void Wait(uint32 index = UINT32_MAX);

	void Reset(uint32 index = UINT32_MAX);

protected:

	std::vector<VkFence> mFences;

};